<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@include file="../../common/mastertopedit.jsp"%>
<script type="text/javascript" src="${ctx}/js/region.js"></script>

<input type="hidden" id="addressId" value="${model.addressId}">
<div class="form-horizontal pt-15  form-clean-magin">
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">配送地名称</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="addressName" id="addressName" maxlength="100" type="text"
				value="${model.customerAddress.addressName}"> <i class="plum-sign-right">*</i>
		</div>
	</div>
 
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">所属客户</label>
		<div class="col-xs-9">
			<select name="customerId"
				id="customerId" class="form-control form-control-260 pull-left">
				<option value=""
					<c:if test="${model.customerAddress.customerId==null}">selected="selected"</c:if>>全部</option>
				<c:forEach items="${model.customers}" var="lo" varStatus="itemStatus">
					<option value="${lo.id}"
						<c:if test="${model.customerAddress.customerId==lo.id}">selected="selected"</c:if>>${lo.customerName}</option>
				</c:forEach>
			</select> <i class="plum-sign-right">*</i>
		</div>
	</div>

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">联系人</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="contacts" id="contacts" maxlength="100" type="text"
				value="${model.customerAddress.contacts}">
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">手机号</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="mobile" id="mobile" maxlength="11" type="text"  pattern="/[^\d]+/" 
				value="${model.customerAddress.mobile}">
		</div>
	</div>
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">座机</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="tel" id="tel" maxlength="100" type="text"
				value="${model.customerAddress.tel}">
		</div>
	</div>
	

	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">邮箱</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="email" id="email" maxlength="100" type="text"
				value="${model.customerAddress.email}">
		</div>
	</div>
		
	
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">省市区</label>
		<div class="col-xs-9">
			<input type="hidden" id="pid" value="${model.customerAddress.provinceId}">
			<input type="hidden" id="cid" value="${model.customerAddress.cityId}">
			<input type="hidden" id="aid" value="${model.customerAddress.areaId}">
			<select id="provinceId" class="form-control form-control-125 pull-left"   onchange="selectProvince()" >
				<option value="" >选择市</option>
			</select>
			<select id="cityId" class="form-control form-control-125 pull-left" onchange="selectCity()" >
				<option value="" >选择市</option>
			</select>
			<select id="areaId" class="form-control form-control-125 pull-left"  >
				<option value="" >选择市</option>
			</select>
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">详细地址</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="addressDesc" id="addressDesc" maxlength="100" type="text"
				value="${model.customerAddress.addressDesc}">
		</div>
	</div>
	
	<div class="form-group">
		<label for="inputEmail3"
			class="col-xs-3 text-right control-label usual-label">备注</label>
		<div class="col-xs-9">
			<input class="form-control form-control-260 pull-left" type="text"
				name="remark" id="remark" maxlength="100" type="text"
				value="${model.customerAddress.remark}">
		</div>
	</div>
	
</div>

<div class="form-group text-center">
	<button type="button" class="runmi-btn runmi-primary"
		onclick="backIndex()">取消</button>
	<button type="button" class="runmi-btn runmi-sure-btn" onclick="save()">保存</button>
</div>
<script type="text/javascript">
	function save() {
		  
  		var addressId=$('#addressId').val();	
		var postData="id=" +addressId ;
		
		var addressName=$('#addressName').val();
		if(addressName=='' && addressName==''){
			layer.alert('请输入配送地址');
	    	return;
		}
		postData=postData + "&addressName=" + encodeURIComponent(addressName);
		
		var customerId=$('#customerId').val();
		if(customerId==''){
			layer.alert('请输入所属客户');
	    	return;
		}
		postData=postData + "&customerId=" + customerId;
		
		/* var stockType= $("input[name='stockType']:checked").val();
		if(stockType==undefined){
			layer.alert('请选择仓库性质');
	    	return;
		}
		postData=postData + "&stockType=" + stockType;
		
		var isInventory= $("input[name='isInventory']:checked").val();
		if(isInventory==undefined){
			layer.alert('请选择是否计入库存');
	    	return;
		}
		postData=postData + "&isInventory=" + isInventory; */
		
		var contacts=$('#contacts').val();
		postData=postData + "&contacts=" + encodeURIComponent(contacts);
		
		var mobile=$('#mobile').val();
		postData=postData + "&mobile=" + encodeURIComponent(mobile);
		if(mobile!=''){
			if(!mobile.isPhone()){
				layer.alert('手机格式错误');
		    	return;
			}
		}
		
		var tel=$('#tel').val();
		postData=postData + "&tel=" + encodeURIComponent(tel);
			
		var email=$('#email').val();
		postData=postData + "&email=" + encodeURIComponent(email);
		if(email!=''){
			if(!email.isEmail()){
				layer.alert('邮箱格式错误');
		    	return;
			}
		}
	
	
		var provinceId=$('#provinceId').val();
		postData=postData + "&provinceId=" + encodeURIComponent(provinceId);
		
		var cityId=$('#cityId').val();
		postData=postData + "&cityId=" + encodeURIComponent(cityId);
		
		var areaId=$('#areaId').val();
		postData=postData + "&areaId=" + encodeURIComponent(areaId);
		
		var addressDesc=$('#addressDesc').val();
		postData=postData + "&addressDesc=" + encodeURIComponent(addressDesc);
		
		var remark=$('#remark').val();
		postData=postData + "&remark=" + encodeURIComponent(remark);
		
		/* var url="updateCustomerAddress";
		if(addressId==''){
			url="saveCustomerAddress";
		} */
		
	    layer.load(1, {shade: [0.5,'#fff']});
	    //alert(url + postData);
	    $.ajax({
	        type: "POST",
	        url: "saveCustomerAddress",
	        data: postData,
	        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	        async: true, // 同步  true 异步。默认是异步
	        dataType: 'json',
	        error: function(resultdata) {
	        	layer.closeAll();
	        },
	        success: function(resultdata) {
	        	layer.closeAll();
	            if(resultdata.returnCode=="0000"){               	
	            	layer.alert('操作成功',{icon: 1}, function(){
	            	 	 parent.editReturn();
	            	});
	            }else{
	            	layer.alert(resultdata.returnMessage);
	            }
	        }
	    });
	}
	function backIndex() {
		parent.editReturn();
	}
</script>
<%@include file="../../common/masterbottom.jsp"%>
